package cn.kgc.javase.collection;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author 课工场
 * @date 2024/8/15
 * @description
 *  Date  日期类
 *  Calendar  日历类
 */
public class DateDemo {

    public static void main(String[] args) {

        Date date = new Date(1723706021270L);
        System.out.println("date = " + date);

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        System.out.println("format = " + format);

        int year = date.getYear();  //  1900
        System.out.println("year = " + year);
        long time = date.getTime();
        System.out.println("time = " + time);

        //  通过getInstance  获取日历类对象
        Calendar calendar = Calendar.getInstance();

        Date time1 = calendar.getTime();
        System.out.println("time1 = " + time1);
        //  获取指定的数据
        int year1 = calendar.get(Calendar.MONTH);
        System.out.println("year1 = " + year1);
    }
}
